package com.atguigu.gulimall.seckill.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(RedisProperties.class)
public class MyRedissonConfig {

    /**
     * 所有对redisson的操作都是通过RedissonClient对象
     *
     * @return
     */
    @Bean(destroyMethod = "shutdown")
    RedissonClient redisson(RedisProperties redisProperties) {
        // 创建配置
        Config config = new Config();
        //可以用 redis:// 当作普通连接协议
        //可以用 rediss:// 来启用SSL连接
        config.useSingleServer().setAddress(
                "redis://" + redisProperties.getHost() + ":" + redisProperties.getPort()
        );
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }
}
